/******************************************************************************
  * Welcome sayfası
  * Login işlemi de bu sayfadan yapılacak
  * @returns {undefined}
  */
 
 __m.welcomeModule={
     me: this,
     url:"/welcome",
     
     simpleInit:function(){
         /**********************************************************************
          * Slider Testi
          *********************************************************************/
         var testSlider=function(){
             __m.welcomeModule.pageSlider.baseSetup("slider");
             $("#btnNext").click(function(){
                    __m.welcomeModule.pageSlider.nextSlide();
             });
             
         }
         
         

         /**********************************************************************
          * Tanıtım alanındaki kolonların animasyon işlemleri
          *********************************************************************/
         var tanitimKolonlarYukle=function(){
                $(".kolon").hover(function(){ 
                    $(this).animate({ backgroundColor: "#ccc" }, 1000);

                    $(this).children(".image-area").css("background-color", "#fff");
                },function(){

                   $(this).children(".image-area").css("background-color", "#fff");
                   $(this).animate({ backgroundColor: "#fff" }, 1000);
               });
         }
         
         
         
         /**********************************************************************
          * Demo Slider kodu
          * Kaldırılacak
          *********************************************************************/
         var setupSliderDemo=function(){       
                $("#btnNext").click(function(){
                    var ml=$("#slider_ic").css("margin-left");
                    ml=ml.substring(0,ml.length-2);
                    var limit=$("#slider_ic").width()-1000;        
                    if(ml>-limit)
                    $("#slider_ic").animate({marginLeft:ml-1000},1000,'swing');
                    else{
                        $("#slider_ic").animate({marginLeft:0},1000,'swing');
                    }
                });
         }
         
         
         
         /**********************************************************************
          * Demo Slider kodu
          * Kaldırılacak
          *********************************************************************/
         var setupTimeredSliderDemo=function(){
             var timer=window.setInterval(onTick, 3000);
             
             function onTick(){                    
                    var ml=$("#slider_ic").css("margin-left");
                    ml=ml.substring(0,ml.length-2);
                    var limit=$("#slider_ic").width()-1000;        
                    if(ml>-limit)
                    $("#slider_ic").animate({marginLeft:ml-1000},1000,'swing');
                    else{
                        $("#slider_ic").animate({marginLeft:0},1000,'swing');
                    }
             }
         }
         
         
         tanitimKolonlarYukle();
//       setupSliderDemo();
//       setupTimeredSliderDemo();
//       testSlider();
         __m.welcomeModule.pageSlider.baseSetup("slider");
         
         
//------------------------------------------------------------------------------
//------- Code Template---------------------------------------------------------
            /**
             * Welcome Sayfasındaki arama butonu
             */
        //    var show=false;
        //    $(".speech-arrow").css("opacity", 0)
        //    $(".speech-bubble").css("opacity", 0);
        //    $("a",".speech-handler").click(function(){
        //        if(!show){
        //            $(this).next(".speech-arrow").animate({opacity:1},1000).next().animate({opacity:1},1000);
        //            show=true;
        //        }else{
        //            $(this).next(".speech-arrow").animate({opacity:0},1000).next().animate({opacity:0},1000);
        //            show=false;
        //        }
        //    });
//------------------------------------------------------------------------------
        
        
        
     }
 };



/******************************************************************************
  * Welcome sayfası Slider Componenti
  * Resim geçiişleri için kendim component yazdım
  * Jquery Tabanlı
  * @returns {undefined}
  */
__m.welcomeModule.pageSlider={    
            
            active:false,
            
            childCount:0,
            
            $baseSliderElem:null,
            
            $baseScrollElem:null,
            
            $navElem:null,
            
            timer:null,
            
            activeSlide:0,
            
            baseSetup:function(sliderElem){
                
                var setupSlider=function(){                   
                    __m.welcomeModule.pageSlider.$baseScrollElem.width(__m.welcomeModule.pageSlider.animSettings.slideWidth * __m.welcomeModule.pageSlider.childCount);
                    __m.welcomeModule.pageSlider.$baseScrollElem.css("margin-left", 0);
                    __m.welcomeModule.pageSlider.activeSlide=0;
                    
//                    alert("child sayısı : " + __m.welcomeModule.pageSlider.childCount);
                    __m.welcomeModule.pageSlider.$navElem.width(__m.welcomeModule.pageSlider.animSettings.navBtnWidth * __m.welcomeModule.pageSlider.childCount);
                    
                        var liElem="<li class='nav-button'></li>";
                        for(var i=0; i<__m.welcomeModule.pageSlider.childCount; i++){
                            __m.welcomeModule.pageSlider.$navElem.append(liElem);
                        }
                        
                    __m.welcomeModule.pageSlider.$navElem.children().eq(0).addClass("active");
                    
                    $(".nav-button").click(function(){
                        var index=$(this).index();
                        __m.welcomeModule.pageSlider.gotoSlide(index);

                    });
                }
                
                
                var setupTimeredSliderAction=function(){
                    __m.welcomeModule.pageSlider.timer=window.setInterval(onTimerTick, 3000);
                }
                
                var onTimerTick=function(){
                    __m.welcomeModule.pageSlider.nextSlide();
                }
                
                
                if($("#"+ sliderElem).length>0){
                    if($("#" + sliderElem).children().length > 0){
                        this.active=true;
//                        this.childCount=$(".slide-content",$("#"+ scrollElemId)).length;
//                        this.$baseScrollElem=$("#"+ scrollElemId);

                        this.$baseSliderElem=$("#" + sliderElem);
//                        alert("slider elem : " + this.$baseSliderElem.length);
                        
                        this.$baseScrollElem=$("#"+ sliderElem +" .slider-scroll");                        
//                        alert("slider scroll : " + this.$baseScrollElem.length);
                        
                        this.$navElem=$("#"+ sliderElem + " .nav-body");
//                        alert("nav : " + this.$navElem.length);
                        
                        this.childCount=this.$baseScrollElem.children().length;
                        
                        setupSlider();
                        setupTimeredSliderAction();
                    }
                }
                
            },
            nextSlide:function(){
                if(this.$baseScrollElem != null){
                    if(this.childCount > 0){
                        
                        if(this.activeSlide <= this.childCount-2){
                            this.activeSlide+=1;
                            
                            this.$baseScrollElem.animate({marginLeft: -this.activeSlide*__m.welcomeModule.pageSlider.animSettings.slideWidth}
                                                                                 ,1000,
                                                                                 __m.welcomeModule.pageSlider.animSettings.ease);
                            this.$navElem.children().eq(this.activeSlide-1).removeClass("active");
                            this.$navElem.children().eq(this.activeSlide).addClass("active");
                        }else{
                             __m.welcomeModule.pageSlider.activeSlide=0;
                             __m.welcomeModule.pageSlider.$baseScrollElem.animate({marginLeft: 0},
                                                                                1000,
                                                                                __m.welcomeModule.pageSlider.animSettings.ease);
                                                                                
                             __m.welcomeModule.pageSlider.$navElem.children().eq(__m.welcomeModule.pageSlider.activeSlide-1).removeClass("active");
                             __m.welcomeModule.pageSlider.$navElem.children().eq(__m.welcomeModule.pageSlider.activeSlide).addClass("active");
                        }
                    }
                }
            },
            gotoSlide:function(i){
                var onTimerTick=function(){
                    __m.welcomeModule.pageSlider.nextSlide();
                }
                if(this.$baseScrollElem != null){
                    if(this.childCount > 0){
                        
                        if(i <= this.childCount-1){
                            this.$baseScrollElem.animate({marginLeft: -i*__m.welcomeModule.pageSlider.animSettings.slideWidth}
                                                                                 ,1000,
                                                                                 __m.welcomeModule.pageSlider.animSettings.ease);
                            this.$navElem.children().eq(this.activeSlide).removeClass("active");
                            this.$navElem.children().eq(i).addClass("active");
                            this.activeSlide=i;
                            
                            window.clearInterval(__m.welcomeModule.pageSlider.timer);
                            __m.welcomeModule.pageSlider.timer=window.setInterval(onTimerTick, 3000);
                        }
                    }
                }
                
            }
     
};



/******************************************************************************
  * Slider Componenti Animasyon ayarları objesi
  * global değişken değerlerini tutacak
  * @returns {undefined}
  */
__m.welcomeModule.pageSlider.animSettings={
        navBtnWidth:18,
        slideWidth:1000,
        duration:1000,
        ease:'swing'            
 };
 
 $(document).ready(function(){
     __m.pageHeader.simpleInit();
     __m.welcomeModule.simpleInit();
 });
